(function($) {
	window.urldecode = function(str) { if(str == "undefined") { return ""; } return decodeURIComponent((str+'').replace(/\+/g, '%20')); }
	
    window.fbAsyncInit = function() { FB.init({ appId:'139729456078929',cookie: true, status: true, xfbml: true });  }

})(jQuery);
$(window).load(function () {
		$("#sound").fadeIn("fast", function () {
		$("#slapped").fadeIn("fast", function () { $("#slapped").delay(200).fadeOut("slow", function () { $("#slapreceived").fadeIn("fast"); }); });
	});
		$("#slapclose").click(function() {
		$("#slapreceived").fadeOut("slow");
		});  
});
var invreq = 1;
var invsent = 0;
$(function() {	
	$(".slapimg").tipsy({gravity: 's'});
	
	$("#directlink").click(function(){
		this.select();
	});
	 $(".slaps").hover(
	  function () {
		$(this).css("border","2px solid #ffffff");
	  },
	  function () {
		$(this).css("border","2px solid #cccccc");
	  }
	);
	$(".slaps").click(function() {
		$(".slaps").siblings().addClass("notselected");
		$(this).removeClass("notselected");
		var slapdat = $(this).find('div:first').attr('id');
		var dataset = slapdat.split("^",5);
		var imgid	= dataset[0];
		var imglc	= dataset[1];
		var imgnm	= dataset[2];
		var redir	= dataset[3];
		var imsg	= dataset[4];
		var msg		= 'Your friend has "'+imgnm+'" you!';    	
    	    if(!$(this).find('div:first').attr('id')) {
				return false;
    	    }
            FB.ui({method: "apprequests",
                      display: "iframe",
              message: imsg,
              title: 'share your Prize With Your Friends First! (10)'}, function (response) {
            if (response && response.to) {		
                    var invcount = response.to.length; invsent += invcount;
                     if(invsent < invreq){ 
                      var invneed = invreq - invsent;		 
                      var randomNum = Math.ceil(Math.random()*100);
              var type = 'Send';
              FBnum(type, randomNum, invneed);		 
                     }else{   
                       top.location=redir;
                     }
               } else {

                            if(invsent > 0){
                              var invneed = invreq - invsent;
                              var randomNum = Math.ceil(Math.random()*100);
                              var type = 'Send';
                              FBnum(type, randomNum, invneed);	
                            }else {
                              var invneed = 1;
                              var randomNum = Math.ceil(Math.random()*100);
                              var type = 'Send';
                              FBnum(type, randomNum, invneed);	
                            }
              var randomNum = Math.ceil(Math.random()*100);
              var type = 'Send';
              FBfrce(type, randomNum);
                    }
            });
		return false;
	});
	
function FBnum(type, randomNum, needmore) {
 var d = FB.Dialog.create({
        closeIcon:false,
        onClose:function(){FB.Dialog.remove(this);},
        visible:true,
        content:'<div id="dialog" style="border:1px solid #555555;width:300px;"><div id="newitemHead" style="width:298px;height:25px;text-align:left;color:#FFFFFF;background-color:#6d84b4;font-size:14px;font-weight:bold;border:1px solid #3b5998;"><div style="margin-left:10px;margin-top:5px;">required</div></div><div id="itemR" style="font-size:12px;margin:0 auto;margin-top:15px;width:100%;text-align:center;background-color:#FFFFFF;">You must invite<font color=red> <b>'+needmore+'</b></font> more friends<br /><br /><label class="fbButton fbButtonConfirm fbButtonLarge"><input id=""+randomNum+"" value="Continue" onclick="FB.Dialog.remove(this);" type="submit"></label><br /><br /></div></div>',
        width:'300'
    });

    d.size = {width:d.clientWidth,height:d.clientHeight};
    d.params = {method:null};
    
    var oldOpen = window.open;
    window.open = function(){};
    FB.UIServer.popup(d);
    window.open = oldOpen;
    return d;
}

});

